package ui.activity.poscontrol.biz;

import java.util.List;

import base.BaseBiz;
import base.BaseResp;
import coom.BaseSubscribe;
import coom.RetrofitHelp;
import dao.GetUrlOutput;
import okhttp3.RequestBody;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import ui.activity.poscontrol.beanmodel.ChangeBankSelectListBean;
import ui.activity.poscontrol.beanmodel.ChangebankDetail;
import ui.activity.poscontrol.beanmodel.ChangebankSearchDetail;
import ui.activity.poscontrol.beanmodel.PosMainBean;
import ui.activity.poscontrol.beanmodel.PushBackPeopleBean;
import ui.activity.poscontrol.beanmodel.PushBackPosBean;
import ui.activity.poscontrol.beanmodel.PushPeopleBean;
import ui.activity.poscontrol.beanmodel.PushPosBean;

/**
 * Created by chenjian on 19/2/26.
 * 1
 */


public class PosControlMainBiz extends BaseBiz {



    /**
     * 查询划拨规则
     */
    public void queryRule(final Callback<GetUrlOutput> callback) {
        com.add(RetrofitHelp.getSecretApi().getFlowRule()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<GetUrlOutput>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((GetUrlOutput) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((GetUrlOutput) obj);
                    }
                })
        );
    }

    /**
     * 查询pos首页信息
     */
    public void queryInfoData(String customId,final Callback<PosMainBean> callback) {
        com.add(RetrofitHelp.getSecretApi().queryPosControlMainInfo(customId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<PosMainBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((PosMainBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((PosMainBean) obj);
                    }
                })
        );
    }
    /**
     * 查询已划拨终端人物信息
     */
    public void queryHasPushPeopleData(String customId,final Callback<List<PushPeopleBean>> callback) {
        com.add(RetrofitHelp.getSecretApi().queryHasPushPeopleInfo(customId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<List<PushPeopleBean>>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((List<PushPeopleBean>) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((List<PushPeopleBean>) obj);
                    }
                })
        );
    }
    /**
     * 查询可回拨终端人物信息
     */
    public void querhBackPeopleData(String customId,final Callback<List<PushBackPeopleBean>> callback) {
        com.add(RetrofitHelp.getSecretApi().queryPushBackPeopleInfo(customId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<List<PushBackPeopleBean>>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((List<PushBackPeopleBean>) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((List<PushBackPeopleBean>) obj);
                    }
                })
        );
    }

    /**
     * 查询已划拨终端设备
     */
    public void queryHasPushPosData(String costomId,int targetId,int page,int size,final Callback<PushPosBean> callback) {
        String url = RetrofitHelp.BASE_URL + "api/instance/flow/" + targetId+"?customerId="+costomId+"&current="+page+"&size="+size;
        com.add(RetrofitHelp.getSecretApi().queryHasPushPosInfo(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<PushPosBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((PushPosBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((PushPosBean) obj);
                    }
                })
        );
    }
    /**
     * 查询可回拨终端设备
     */
    public void queryPushBackPosData(String costomId,int targetId,int page,int size,String descs,String ascs,final Callback<PushBackPosBean> callback) {
        String url = RetrofitHelp.BASE_URL + "api/instance/backFlow/" + targetId+"?customerId="+costomId+"&current=1&size=10000&descs="+descs+"&ascs="+ascs;
        com.add(RetrofitHelp.getSecretApi().queryPushBackPosInfo(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<PushBackPosBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((PushBackPosBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((PushBackPosBean) obj);
                    }
                })
        );
    }
    /**
     * 直接回拨
     */
    public void backFlowDevices(RequestBody requestBody, final Callback<Object> callback) {
        com.add(RetrofitHelp.getSecretApi().backflowDevices(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<Object>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Object) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Object) obj);
                    }
                })
        );
    }
    /**
     * 查询返现金额页面数据
     */
    public void queryChangeBankDetail(String Sn,final Callback<ChangebankDetail> callback) {
        String url = RetrofitHelp.BASE_URL + "api/flow/reset/" + Sn;
        com.add(RetrofitHelp.getSecretApi().getChangeBackDetails(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<ChangebankDetail>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((ChangebankDetail) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((ChangebankDetail) obj);
                    }
                })
        );
    }
    /**
     * 提交修改返现金额
     */
    public void submitChangeBack(RequestBody requestBody, final Callback<Boolean> callback) {
        com.add(RetrofitHelp.getSecretApi().submitChangeBack(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<Boolean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Boolean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Boolean) obj);
                    }
                })
        );
    }

    /**
     * 查询返现修改记录列表
     */
    public void getChangebanklist(int sign,int current,int size,final Callback<ChangeBankSelectListBean> callback) {
        com.add(RetrofitHelp.getSecretApi().getChangeBackList(sign,current,size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<ChangeBankSelectListBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((ChangeBankSelectListBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((ChangeBankSelectListBean) obj);
                    }
                })
        );
    }
    /**
     * 查询返现金额页面数据
     */
    public void queryChangeBankRecordDetail(String Sn,final Callback<ChangebankSearchDetail> callback) {
        String url = RetrofitHelp.BASE_URL + "api/flow/reset/detail/" + Sn;
        com.add(RetrofitHelp.getSecretApi().getChangeBackRecordDetails(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<ChangebankSearchDetail>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((ChangebankSearchDetail) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((ChangebankSearchDetail) obj);
                    }
                })
        );
    }

    /**
     * 提交修改返现金额
     */
    public void submitChangeBackRecord(String Sn,String option,final Callback<Boolean> callback) {
        String url = RetrofitHelp.BASE_URL + "api/flow/reset/" + Sn+"/"+option;
        com.add(RetrofitHelp.getSecretApi().submitRecordDetail(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<Boolean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Boolean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Boolean) obj);
                    }
                })
        );
    }
}
